using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;

namespace CodexOmega.Modules.VideoLinker
{
    public class VideoLinkerController
    {

        #region Constructors

        public VideoLinkerController()
        {
        }

        #endregion

        #region Public Methods

        public int CreateVideoLink(VideoLinkerInfo videoLinkerInfo)
        {
            return DataProvider.Instance().CreateVideoLink(videoLinkerInfo);
        }

        public bool DeleteVideoLink(int videoID)
        {
            bool isDeleted = false;

            DataProvider.Instance().DeleteVideoLink(videoID);

            return isDeleted;
        }

        public VideoLinkerInfo GetVideoLink(int videoID)
        {
            return DataProvider.Instance().GetVideoLink(videoID);
        }

        public List<VideoLinkerInfo> GetVideoLinksList(int typeID, int categoryID, string keyword, string sortParameter)
        {
            List<VideoLinkerInfo> listVideos = DataProvider.Instance().GetVideoLinksList(typeID, categoryID, keyword);

            if (listVideos != null && !string.IsNullOrEmpty(sortParameter))
            {
                // split sort parameter
                string[] splittedExpr = sortParameter.Split(' ');

                // get sort element
                string sortElement = splittedExpr[0];

                // get sort direction
                string sortDirection = "asc";
                if (splittedExpr.Length == 2)
                {
                    sortDirection = splittedExpr[1];
                }

                // sort list
                if (sortDirection.ToLower() == "asc")
                {
                    listVideos.Sort(new CodexStar.Framework.Utils.GenericComparer<VideoLinkerInfo>(sortElement, System.Web.UI.WebControls.SortDirection.Ascending));
                }
                else
                {
                    listVideos.Sort(new CodexStar.Framework.Utils.GenericComparer<VideoLinkerInfo>(sortElement, System.Web.UI.WebControls.SortDirection.Descending));
                }
            }

            return listVideos;
        }

        public bool UpdateVideoLink(VideoLinkerInfo videoLinkerInfo)
        {
            return DataProvider.Instance().UpdateVideoLink(videoLinkerInfo);
        }

        public Dictionary<string, int> GetVideoCategoriesList()
        {
            return DataProvider.Instance().GetVideoCategoriesList();
        }

        public Dictionary<string, int> GetVideoTypesList()
        {
            return DataProvider.Instance().GetVideoTypesList();
        }

        public string GetVideoCategory(int categoryID)
        {
            return DataProvider.Instance().GetVideoCategory(categoryID);
        }

        public string GetVideoType(int typeID)
        {
            return DataProvider.Instance().GetVideoType(typeID);
        }

        public int CreateVideoCategory(string definition)
        {
            return DataProvider.Instance().CreateVideoCategory(definition);
        }

        public int CreateVideoType(string definition)
        {
            return DataProvider.Instance().CreateVideoType(definition);
        }

        public bool UpdateVideoCategory(int categoryID, string definition)
        {
            return DataProvider.Instance().UpdateVideoCategory(categoryID, definition);
        }

        public bool UpdateVideoType(int typeID, string definition)
        {
            return DataProvider.Instance().UpdateVideoType(typeID, definition);
        }

        public bool DeleteVideoCategory(int categoryID)
        {
            return DataProvider.Instance().DeleteVideoCategory(categoryID);
        }

        public bool DeleteVideoType(int typeID)
        {
            return DataProvider.Instance().DeleteVideoType(typeID);
        }

        
        #endregion

    }
}

